<template>
  <div class="header-box">
    <div class="header">
      <div class="content">
        <div class="logo full-left">
          <router-link to="/"><img src="/static/image/logo.png" alt=""></router-link>
        </div>
        <!-- 导航栏 -->
        <ul class="nav full-left">
          <li v-for="nav in nav_list" :key="nav.id">
            <span v-if="nav.is_site">
              <!-- 如果是站外地址  用 a-->
              <a :href="nav.link">{{nav.title}}</a>
            </span>
            <span v-else>
              <!-- 站内地址 用router-link -->
              <router-link :to="nav.link">{{nav.title}}</router-link>
            </span>
          </li>
          
        </ul>
        <div class="login-bar full-right">
          <div class="shop-cart full-left">
            <img src="/static/image/cart.svg" alt="">
            <span><router-link to="/cart">购物车</router-link></span>
          </div>
          <div class="login-box full-left">
            <span>登录</span>&nbsp;|&nbsp;<span>注册</span>
          </div>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  name: "HeaderComp",
  data(){
    return{
      nav_list:[]
    }
  },
  created(){
    this.get_nav()
  },
  methods: {
    // 获取顶部导航数据
    get_nav(){
      this.$axios.get(`${this.$settings.Host}/home/nav/header`, {}).then(res=>{
        this.nav_list = res.data
        console.log(this.nav_list)
      })
    }
  }
}
</script>

<style scoped>
.header-box {
  height: 60px;
}

.header {
  width: 100%;
  height: 60px;
  box-shadow: 0 0.5px 0.5px 0 #c9c9c9;
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  margin: auto;
  z-index: 99;
  background: #fff;
}

.header .content {
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 20px;
  height: 100%;
}

.header .content .logo {
  height: 60px;
  line-height: 60px;
  margin-right: 50px;
  cursor: pointer;
}

.header .content .logo img {
  vertical-align: middle;
  height: 40px;
  transition: transform 0.3s ease;
}

.header .content .logo img:hover {
  transform: scale(1.1);
}

.nav {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-grow: 1;
  margin: 0 auto;
}

.nav li {
  margin-right: 20px;
  font-size: 16px;
  color: #4a4a4a;
  cursor: pointer;
  transition: color 0.3s ease;
}

.nav li:hover {
  color: #6a11cb;
}

.login-bar {
  display: flex;
  align-items: center;
  height: 100%;
}

.shop-cart {
  margin-right: 20px;
  border-radius: 20px;
  background: linear-gradient(135deg, #6a11cb 0%, #2575fc 100%);
  cursor: pointer;
  font-size: 12px;
  height: 32px;
  width: 100px;
  line-height: 32px;
  text-align: center;
  position: relative;
  transition: all 0.3s ease;
  box-shadow: 0 4px 6px rgba(0, 0, 0, 0.1);
}

.shop-cart:hover {
  background: linear-gradient(135deg, #2575fc 0%, #6a11cb 100%);
  transform: translateY(-2px);
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.2);
}

.shop-cart img {
  width: 16px;
  height: 16px;
  vertical-align: middle;
  margin-right: 6px;
  filter: brightness(0) invert(1);
}

.shop-cart span {
  color: #fff;
  font-weight: 500;
}

.login-box {
  margin-left: 20px;
}

.login-box a {
  color: #4a4a4a;
  font-weight: 500;
  text-decoration: none;
  transition: color 0.3s ease;
  padding: 8px 12px;
  border-radius: 20px;
}

.login-box a:hover {
  color: #6a11cb;
  background: rgba(106, 17, 203, 0.1);
}

@media (max-width: 768px) {
  .header .content {
    padding: 0 10px;
  }

  .nav {
    display: none;
  }

  .shop-cart {
    width: auto;
    padding: 0 15px;
  }

  .shop-cart img {
    margin-right: 5px;
  }

  .shop-cart span {
    display: none;
  }

  .login-box {
    margin-top: 15px;
  }

  .login-box a {
    padding: 6px 10px;
    font-size: 14px;
  }
}
</style>